﻿package me.zhengjie.common.base

import cn.hutool.core.bean.BeanUtil
import cn.hutool.core.bean.copier.CopyOptions
import com.fasterxml.jackson.annotation.JsonTypeName
import me.zhengjie.common.utils.JacksonUtil
import java.sql.Timestamp


/**
 * @author Kuki
 * @Date 2024/11/10
 */
@JsonTypeName("BaseDTO")
open class BaseDTO (
    var createBy: String? = null,
    var updateBy: String? = null,
    var createTime: Timestamp? = null,
    var updateTime: Timestamp? = null
){
    annotation class Update

    companion object {
        fun fromJson(json: String): BaseDTO? {
            val obj=JacksonUtil.parseObject(json, BaseDTO::class.java)!!
            return when(obj){
                is BaseDTO -> obj
                else -> null
            }
        }
    }

    fun tojson():String? {
        return JacksonUtil.toJSONString(this)
    }

    fun copy(source: BaseDTO?) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true))
    }
}
